<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="采购方总部编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag v-decorator="[ 'purchaserHqCode', validatorRules.purchaserHqCode, {}]" :triggerChange="true" placeholder="请选择采购方总部" dictCode="purchaserHqCode"/>
        </a-form-item>
        <a-form-item label="供应商名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag @change="handleInput" v-decorator="[ 'supplierCode', validatorRules.supplierCode, {}]" :triggerChange="true" placeholder="请选择供应商名称" dictCode="kggSupplierCode" />
          <a-input v-model="model.supplierName" type="hidden"/>
        </a-form-item>
        <a-form-item label="供应商工单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierWorkNo', validatorRules.supplierWorkNo, {}]" placeholder="请输入供应商工单编号"></a-input>
        </a-form-item>
        <a-form-item label="采集规范版本号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'standardVersion', validatorRules.standardVersion, {}]" disabled></a-input>
        </a-form-item>
        <a-form-item label="规格型号编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag v-decorator="[ 'modelCode', validatorRules.modelCode, {}]" :triggerChange="true" placeholder="请选择规格型号编码" dictCode="kggModelCode"/>
        </a-form-item>
        <a-form-item label="物资品类类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag v-decorator="[ 'categoryType', validatorRules.categoryType]" :triggerChange="true" placeholder="请选择物资品类类型" dictCode="kggCategoryType"/>
        </a-form-item>
        <a-form-item label="采集时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择采集时间" showTime="true" dateFormat="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'checkTime', validatorRules.checkTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="入数采中心时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择入数采中心时间" showTime="true" dateFormat="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'putCenterTime', validatorRules.putCenterTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="工序" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'pdCode', validatorRules.pdCode]" placeholder="请输入工序"></a-input>
        </a-form-item>
        <a-form-item label="感知过程" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processType', validatorRules.processType]" placeholder="请输入感知过程"></a-input>
        </a-form-item>
        <a-form-item label="厂区编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'factoryCode', validatorRules.factoryCode]" placeholder="请输入厂区编号"></a-input>
        </a-form-item>
        <a-form-item label="供应商产品编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierSupportId', validatorRules.supplierSupportId]" placeholder="请输入供应商产品编号"></a-input>
        </a-form-item>
        <a-form-item label="供应商数据唯一标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productModel', validatorRules.productModel]" placeholder="请输入供应商数据唯一标识"></a-input>
        </a-form-item>
        <a-form-item label="生产设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'equipmentName', validatorRules.equipmentName]" placeholder="请输入生产设备名称"></a-input>
        </a-form-item>
        <a-form-item label="生产设备唯一识别号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'equipmentUniqueCode', validatorRules.equipmentUniqueCode]" placeholder="请输入生产设备唯一识别号"></a-input>
        </a-form-item>
        <a-form-item label="断路器处于合闸位置时，断路器小车无法推进或拉出。" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag v-decorator="[ 'breakerClosed', validatorRules.breakerClosed, {}]" :triggerChange="true" placeholder="请选择断路器处于合闸位置时，断路器小车无法推进或拉出。" dictCode="isTrue"/>
        </a-form-item>
        <a-form-item label="断路器小车未到工作或试验位置时，断路器无法进行合闸操作。" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag v-decorator="[ 'breakerNotInTest', validatorRules.breakerNotInTest, {}]" :triggerChange="true" placeholder="请选择断路器小车未到工作或试验位置时，断路器无法进行合闸操作。" dictCode="isTrue"/>
        </a-form-item>
        <a-form-item label="断路器手车处于试验位置时，二次插头才可以拔出或插上。" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag v-decorator="[ 'breakerInTest', validatorRules.breakerInTest, {}]" :triggerChange="true" placeholder="请选择断路器手车处于试验位置时，二次插头才可以拔出或插上。" dictCode="isTrue"/>
        </a-form-item>
        <a-form-item label="当接地开关处在合闸位置时，断路器小车无法从试验位置进入工作位置。" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag v-decorator="[ 'earthSwitchOn', validatorRules.earthSwitchOn, {}]" :triggerChange="true" placeholder="请选择当接地开关处在合闸位置时，断路器小车无法从试验位置进入工作位置。" dictCode="isTrue"/>
        </a-form-item>
        <a-form-item label="断路器手车处于工作位置时，无法操作接地开关。" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag v-decorator="[ 'breakerInWorking', validatorRules.breakerInWorking, {}]" :triggerChange="true" placeholder="请选择断路器手车处于工作位置时，无法操作接地开关。" dictCode="isTrue"/>
        </a-form-item>
        <a-form-item label="只有当接地开关处于闭合状态时，才能打开电缆室门。" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag v-decorator="[ 'earthSwitchClosed', validatorRules.earthSwitchClosed, {}]" :triggerChange="true" placeholder="请选择只有当接地开关处于闭合状态时，才能打开电缆室门。" dictCode="isTrue"/>
        </a-form-item>
        <a-form-item label="电缆室门打开时，无法操作接地开关。" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag v-decorator="[ 'cableChamberDoorOpen', validatorRules.cableChamberDoorOpen, {}]" :triggerChange="true" placeholder="请选择电缆室门打开时，无法操作接地开关。" dictCode="isTrue"/>
        </a-form-item>
        <a-form-item label="只有当隔室的元件不带电并接地时，隔室的门或盖板才能打开。" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag v-decorator="[ 'elementUnchargedGround', validatorRules.elementUnchargedGround, {}]" :triggerChange="true" placeholder="请选择只有当隔室的元件不带电并接地时，隔室的门或盖板才能打开。" dictCode="isTrue"/>
        </a-form-item>
        <a-form-item>
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" type="hidden"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import {initDictOptions, filterDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: "EipElectricalInterlockModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        kggSupplierCodeDictOptions:[],
        validatorRules:{
        puid:{},
        purchaserHqCode:{rules: [{ required: true, message: '请输入采购方总部编码!' }],initialValue:'SGCC'},
        supplierCode:{rules: [{ required: true, message: '请输入侧供应商编码!' }]},
        supplierName:{rules: [{ required: true, message: '请输入供应商名称!' }]},
        supplierWorkNo:{rules: [{ required: true, message: '请输入供应商工单编号!' }]},
        standardVersion: {rules: [{required: true, message: '请输入采集规范版本号!'}],initialValue:'1'},
        modelCode:{rules: [{ required: true, message: '请输入规格型号编码!' }],initialValue:'gear00001'},
        categoryType:{rules: [{ required: true, message: '请输入物资品类类型!' }],initialValue:'90001'},
        checkTime:{rules: [{ required: true, message: '请输入采集时间!' }]},
        putCenterTime:{rules: [{ required: true, message: '请输入入数采中心时间!' }]},
        pdCode:{rules: [{ required: true, message: '请输入工序!' }],initialValue:'GX000018'},
        processType:{rules: [{ required: true, message: '请输入感知过程!' }],initialValue:'3'},
        factoryCode:{},
        supplierSupportId:{},
        productModel:{rules: [{ required: true, message: '请输入供应商数据唯一标识!' }]},
        equipmentName:{rules: [{ required: true, message: '请输入生产设备名称!' }]},
        equipmentUniqueCode:{rules: [{ required: true, message: '请输入生产设备唯一识别号!' }]},
        breakerClosed:{rules: [{ required: true, message: '请输入断路器处于合闸位置时，断路器小车无法推进或拉出。!' }]},
        breakerNotInTest:{rules: [{ required: true, message: '请输入断路器小车未到工作或试验位置时，断路器无法进行合闸操作。!' }]},
        breakerInTest:{rules: [{ required: true, message: '请输入断路器手车处于试验位置时，二次插头才可以拔出或插上。!' }]},
        earthSwitchOn:{rules: [{ required: true, message: '请输入当接地开关处在合闸位置时，断路器小车无法从试验位置进入工作位置。!' }]},
        breakerInWorking:{rules: [{ required: true, message: '请输入断路器手车处于工作位置时，无法操作接地开关。!' }]},
        earthSwitchClosed:{rules: [{ required: true, message: '请输入只有当接地开关处于闭合状态时，才能打开电缆室门。!' }]},
        cableChamberDoorOpen:{rules: [{ required: true, message: '请输入电缆室门打开时，无法操作接地开关。!' }]},
        elementUnchargedGround:{rules: [{ required: true, message: '请输入只有当隔室的元件不带电并接地时，隔室的门或盖板才能打开。!' }]},
        ioflag:{rules: [{ required: true, message: '请输入状态表示!' }],initialValue:'1'},
        message:{},
        remark1:{},
        remark2:{},
        remark3:{},
        remark4:{},
        remark5:{},
        },
        url: {
          add: "/eipElectricalInterlock/add",
          edit: "/eipElectricalInterlock/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      handleInput(e){
        this.model.supplierName = filterDictText(this.kggSupplierCodeDictOptions, e);
      },
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,"puid", "purchaserHqCode", "supplierCode", "supplierName", "supplierWorkNo", "standardVersion", "modelCode", "categoryType", "checkTime", "putCenterTime", "pdCode", "processType", "factoryCode", "supplierSupportId", "productModel", "equipmentName", "equipmentUniqueCode", "breakerClosed", "breakerNotInTest", "breakerInTest", "earthSwitchOn", "breakerInWorking", "earthSwitchClosed", "cableChamberDoorOpen", "elementUnchargedGround", "ioflag", "message", "remark1", "remark2", "remark3", "remark4", "remark5"))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.puid){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,"puid", "purchaserHqCode", "supplierCode", "supplierName", "supplierWorkNo", "standardVersion", "modelCode", "categoryType", "checkTime", "putCenterTime", "pdCode", "processType", "factoryCode", "supplierSupportId", "productModel", "equipmentName", "equipmentUniqueCode", "breakerClosed", "breakerNotInTest", "breakerInTest", "earthSwitchOn", "breakerInWorking", "earthSwitchClosed", "cableChamberDoorOpen", "elementUnchargedGround", "ioflag", "message", "remark1", "remark2", "remark3", "remark4", "remark5"))
      }
    },
    mounted() {
      initDictOptions('kggSupplierCode').then((res) => {
        if (res.success) {
          this.kggSupplierCodeDictOptions = res.result
        }
      });
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>